package com.fortune.service.impl;

import com.faneui.common.exception.BusinessException;
import com.faneui.common.utils.ListUtils;
import com.fortune.dal.dao.CreditCardInfoDAO;
import com.fortune.dal.model.CreditCardInfo;
import com.fortune.service.CreditCardInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CreditCardInfoServiceImpl implements CreditCardInfoService {

    @Autowired
    private CreditCardInfoDAO creditCardInfoDAO;

    @Override
    public void addCreditCardInfo(CreditCardInfo creditCardInfo) throws BusinessException {
        try{
            creditCardInfoDAO.insert(creditCardInfo);
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public void modifyCreditCardInfo(CreditCardInfo creditCardInfo) throws BusinessException {
        try{
            creditCardInfoDAO.updateById(creditCardInfo) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public CreditCardInfo queryCreditCardInfo(Integer creditCardInfoId) throws BusinessException {
        CreditCardInfo c = null;
        try{
            c = creditCardInfoDAO.queryById(creditCardInfoId) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return c;
    }

    @Override
    public CreditCardInfo queryCreditCardInfoByCardId(Integer cardId) throws BusinessException {
        CreditCardInfo param = new CreditCardInfo();
        param.setCardId(cardId);
        List<CreditCardInfo> infos = queryCreditCardInfoList(param) ;
        if(ListUtils.isNotEmpty(infos))  {
            return infos.get(0) ;
        }
        return null;
    }

    @Override
    public List<CreditCardInfo> queryCreditCardInfoList(CreditCardInfo creditCardInfo) throws BusinessException {
        List<CreditCardInfo> list = null;
        try{
            list = creditCardInfoDAO.queryByModel(creditCardInfo) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return list;
    }
}
